package org.acompanhamento.domain;

import static javax.persistence.FetchType.LAZY;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import jmine.tec.aom.domain.Property;
import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Index;
import bancosys.tec.component.Documentation;
import bancosys.tec.persist.persister.annotation.NaturalKey;

/**
 * 
 * @author lundberg
 *
 */
@Entity
@Table(name = "TEAM")
@Alias("TEAM")
@Documentation("AGILE TEAMS")
@SequenceGenerator(name = "SEQ_TEAM", sequenceName = "SEQ_TEAM")
public class Team extends PropertizedEntity {

	private Long id;

	private String name;

	private Collection<Member> members;

	@Id
	@GeneratedValue(generator = "SEQ_TEAM")
	@Column(name = "COD_TEAM", nullable = false)
	@Documentation("TEAM ID")
	public Long getId() {
		return this.id;
	}

	@NaturalKey
	@Index(suffix = "0")
	@Column(name = "NAME", nullable = false)
	@Documentation("TEAM NAME")
	public String getName() {
		return this.name;
	}

	@ManyToMany(fetch = LAZY)
	@JoinTable(name = "TEAM_MEMBERSHIP", joinColumns = @JoinColumn(name = "COD_TEAM"), inverseJoinColumns = @JoinColumn(name = "COD_MEMBER"))
	@Alias("TEAMEM")
	public Collection<Member> getMembers() {
		return this.members;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setMembers(Collection<Member> members) {
		this.members = members;
	}

	@Override
	@Transient
	protected Set<Property> getEntityProperties() {
		return Collections.emptySet();
	}

	@Override
	public String toString() {
		return this.getName();
	}
}
